import Vue from 'vue'
import VueRouter from 'vue-router'
import Movie from '../views/home/Movie.vue'

Vue.use(VueRouter)

const routes = [
  {path:"/",redirect:"/home"},
  {
    path: '/home',
    name: 'Movie',
    component: Movie,
    children:[
      {path:"/home",redirect:"/home/MovieChild/reying"},
      {path: 'MovieChild/reying',name: 'reying',component: () => import(/* webpackChunkName: "about" */ '../views/home/MovieChild/reying.vue')},
      {path: 'MovieChild/yingyuan',name: 'yingyuan',component: () => import(/* webpackChunkName: "about" */ '../views/home/MovieChild/yingyuan.vue')},
      {path: 'MovieChild/daiying',name: 'daiying',component: () => import(/* webpackChunkName: "about" */ '../views/home/MovieChild/daiying.vue')},
      {path: 'MovieChild/jingdian',name: 'jingdian',component: () => import(/* webpackChunkName: "about" */ '../views/home/MovieChild/jingdian.vue')},
    ]
  },
  {
    path: '/video',
    name: 'Video',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Video.vue')
  },
  {
    path: '/Movie',
    name: 'Movie',

    component: () => import(/* webpackChunkName: "Movie" */ '../views/home/Movie.vue')
  },
  {
    path: '/MiniVideo',
    name: 'MiniVideo',

    component: () => import(/* webpackChunkName: "MiniVideo" */ '../views/MiniVideo.vue')
  },
  {
    path: '/Show',
    name: 'Show',

    component: () => import(/* webpackChunkName: "Show" */ '../views/Show.vue')
  },
  {
    path: '/Me',
    name: 'Me',

    component: () => import(/* webpackChunkName: "Me" */ '../views/Me.vue')
  },
    //内容页的路由
  {
    path: '/item/:id',//动态路由
    name: 'Item',

    component: () => import(/* webpackChunkName: "item" */ '../views/Item.vue')
  },
  //登录页的路由
  {
    path: '/login',
    name: 'Login',

    component: () => import(/* webpackChunkName: "login" */ '../views/Login.vue')
  },
  //城市的路由
  {
    path: '/City',
    name: 'City',

    component: () => import(/* webpackChunkName: "City" */ '../views/City.vue')
  },
    //404页面配置  必须在路由表的最后配置
  {
    path: '*',
    name: 'page404',

    component: () => import(/* webpackChunkName: "page404" */ '../views/Page404.vue')
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

//添加全局守卫
router.beforeEach((to,from, next)=>{
  if (to.path == '/Me'){//用户中心，需要守卫
    if (sessionStorage.getItem('loginType')){
      next();
    }else {
      next('/Login');
    }
  }else {
    next();
  }
})

export default router
